package edu.scau.cxq.gp.exception;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotRoleException;
import edu.scau.cxq.gp.common.result.MyResult;
import edu.scau.cxq.gp.common.utils.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 简易全局异常处理
 */
@Slf4j
@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = NotLoginException.class)
	public MyResult notLoginExceptionHandler(NotLoginException e){
    	log.warn(ExceptionUtils.getMessage(e));
       	return MyResult.fail(401);
    }

    @ExceptionHandler(value = NotRoleException.class)
	public MyResult notRoleExceptionHandler(NotRoleException e) {
		log.warn(ExceptionUtils.getMessage(e));
    	return MyResult.fail(4011, "你的权限不足！");
	}

	@ExceptionHandler(value = Exception.class)
	public MyResult exceptionHandler(Exception e){
	    log.error(ExceptionUtils.getMessage(e));
		return MyResult.fail(500);
	}


}

